#include "memory_stream.h"

namespace umtl
{
	memory_buffer::memory_buffer( char* p, size_t n ) : std::basic_streambuf<char>()
	{
		setg(p, p, p+n);
		setp(p, p+n);
	}

	char const* memory_buffer::begin_read_buffer() const
	{
		return eback();
	}

	char const* memory_buffer::begin_write_buffer() const
	{
		return pbase();
	}

	char const* memory_buffer::current_write_buffer() const
	{
		return pptr();
	}

	char const* memory_buffer::current_read_buffer() const
	{
		return gptr();
	}

	memory_stream::memory_stream(memory_buffer& buffer) : std::iostream(&buffer), buffer_(buffer)
	{

	}

	char const* memory_stream::begin_read_buffer() const
	{
		return buffer_.begin_read_buffer();
	}

	char const* memory_stream::begin_write_buffer() const
	{
		return buffer_.begin_write_buffer();
	}

	char const* memory_stream::current_write_buffer() const
	{
		return buffer_.current_write_buffer();
	}

	char const* memory_stream::currnet_read_buffer() const
	{
		return buffer_.current_read_buffer();
	}

}